/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.lidejia.xml2pojo.parser;

import com.snda.lidejia.xml2pojo.util.ParserArgumentChecker;
import org.dom4j.Element;
import org.dom4j.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author lidejia
 */
public class XMLFloatParser implements XMLParser {

    private static final Logger LOGGER = LoggerFactory.getLogger(XMLDoubleParser.class);

    public Object parse(Class<?> type, Node... nodes) {
        //
        ParserArgumentChecker.checkSingle(nodes);
        //
        Node node = nodes[0];
        Float value = null;
        String strValue = node.getText().trim();
        if (strValue != null) {
            try {
                value = Float.parseFloat(strValue);
            } catch (NumberFormatException ex) {
                LOGGER.warn("Value is not float: {}", node.getPath());
            }
        }
        return value;
    }
}
